package uk.co.revisual.puremvc.loader.factories
{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	
	import uk.co.revisual.puremvc.loader.interfaces.ICreate;
	
	public class DisplayObjectFactory implements ICreate
	{
		private var mAsset:DisplayObject
		
		public function DisplayObjectFactory(asset:DisplayObject)
		{
			mAsset = asset;
		}
		
		public function create(id:String = ""):*
		{
			var clazz:Class
			
			switch(true)
			{
				case(id == "asset"):
					return mAsset;
					
				case(mAsset is Sprite ):
					clazz = Class(mAsset.loaderInfo.applicationDomain.getDefinition(id));
					return new Class();

				default:
					throw new Error("returning a null object");
					
			}
			
			
		}

	}
}